{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e78e88c9-073f-425f-8f10-4c39ec5fe1df",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集数据的预测标签为 [0 1 1 0 2 2 2 0 0 2 1 0 2 1 1 0 1 1 0 0 1 1 2 0 2 1 0 0 1 2 1 2 1 2 2 0 1\n",
      " 0 1 2 2 0 1 2 1 2 0 0 0 1]\n",
      "测试集数据的真实标签为 [0 1 1 0 2 1 2 0 0 2 1 0 2 1 1 0 1 1 0 0 1 1 1 0 2 1 0 0 1 2 1 2 1 2 2 0 1\n",
      " 0 1 2 2 0 2 2 1 2 0 0 0 1]\n",
      "测试集共有50条数据，其中预测错误的数据有3条，预测准确率为0.94\n"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import load_iris\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.metrics import accuracy_score\n",
    "x,y=load_iris().data,load_iris().target\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=1,test_size=50)\n",
    "model=GaussianNB()\n",
    "model.fit(x_train,y_train)\n",
    "pred=model.predict(x_test)\n",
    "print(\"测试集数据的预测标签为\",pred)\n",
    "print(\"测试集数据的真实标签为\",y_test)\n",
    "print(\"测试集共有%d条数据，其中预测错误的数据有%d条，预测准确率为%.2f\"%(x_test.shape[0],(pred!=y_test).sum(),accuracy_score(y_test,pred)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1df42121-d0b6-4c1a-84d6-ae552c60b6aa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
